package com.java.tutorials.spring.ApplicationContext;

import com.java.tutorials.spring.SpringTesterBase;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Created by xuzhike on 2016/1/28.
 * http://www.java2s.com/Code/Java/Spring/ApplicationContextAware.htm
 */
public class ApplicationContextAwareDemo extends SpringTesterBase {
    @Test
    public void testContextAwareDemo(){
        ContextAwareDemo demo = (ContextAwareDemo) ctx.getBean("contextAware");
        demo.displayAppContext();
    }
}

class ContextAwareDemo implements ApplicationContextAware {
    private ApplicationContext ctx1;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ctx1 = applicationContext;
    }

    public void displayAppContext() {
        System.out.println(ctx1);
    }

}

